package com.cuckoo.mall.thus.menuaccount.language;

import android.support.annotation.Nullable;

import com.bgn.baseframe.utils.LanguageUtil;
import com.bgn.baseframe.utils.UiUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cuckoo.mall.R;
import com.cuckoo.mall.javabean.LanguageItem;

import java.util.List;

/**
 * Created by wanglun on 2018/3/19.
 */

public class LanguageListAdapter extends BaseQuickAdapter<LanguageItem, BaseViewHolder> {
    private int selectPosition;

    public LanguageListAdapter(int layoutResId, @Nullable List<LanguageItem> data) {
        super(layoutResId, data);
        String name = LanguageUtil.getSavedLanguage2Country();
        for (int i = 0; i < data.size(); i++) {
            if (name.startsWith(data.get(i).getCode())) {
                selectPosition = i;
                break;
            }
        }
    }

    public void setSelectPosition(int position) {
        selectPosition = position;
    }

    @Override
    protected void convert(BaseViewHolder helper, LanguageItem item) {
        helper.setText(R.id.tv_item, item.getName());
        helper.setImageResource(R.id.iv_item, item.getImage());
        if (selectPosition == helper.getAdapterPosition()) {
            helper.setBackgroundColor(R.id.rly_root, UiUtil.getColor(R.color.gainsboro));
        } else {
            helper.setChecked(R.id.rly_root, false);
        }
    }
}